package com.yycx.module.bus.provider.handler.haiying.tasktodo.refundamount;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.GetInterceptor;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.utils.DateUtils;
import com.yycx.module.bus.client.entity.BusCustom;
import com.yycx.module.bus.client.entity.BusDeposit;
import com.yycx.module.bus.client.entity.BusDept;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.provider.service.BusCustomService;
import com.yycx.module.bus.provider.service.BusDepositService;
import com.yycx.module.bus.provider.service.BusPaymentService;
import com.yycx.module.file.provider.service.SysFileService;
import com.yycx.module.system.client.entity.SysBank;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 退质押金详情
 *
 * @author zyf
 */
@Component
public class HyRefundDepositGetHandler implements GetInterceptor {

    @Autowired
    private BusDepositService depositService;

    @Autowired
    private SysFileService fileService;


    @Autowired
    private BusCustomService customService;


    @Override
    public ResultBody validate(CriteriaQuery cq, EntityMap params) {
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaQuery cq, EntityMap entityMap) {
        cq.select(BusPayment.class, "*");
    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        Long depositId = map.getLong("orderId");
        BusDeposit deposit = depositService.getById(depositId);
        Map result = BeanUtil.beanToMap(deposit, false, true);
        if (FlymeUtils.isNotEmpty(result)) {
            map.putAll(result);
            Date date = map.get("payDate");
            map.put("payDate", DateUtils.formatDate(date));
            Long customId = deposit.getCustomId();
            BusCustom custom = customService.getById(customId);
            map.put("customName", custom.getCustomName());

        }
    }
}
